from django.http import JsonResponse
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView, ListCreateAPIView, RetrieveUpdateDestroyAPIView
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin, UpdateModelMixin, DestroyModelMixin

from .models import BookInfo
from .serializer import BookSerializer


class BooksView(ListCreateAPIView):
    """获取所有图书、保存图书"""

    queryset = BookInfo.objects.all()  # 指定当前类视图使用的查询集数据
    serializer_class = BookSerializer  # 指定当前类视图使用的序列化器


class BookView(RetrieveUpdateDestroyAPIView):
    """获取单一图书、更新图书、删除图书"""

    queryset = BookInfo.objects.all()
    serializer_class = BookSerializer


